/*
 ============================================================================
 Name		: stopwatchContainer.h
 Author	  : Huang.haiyang
 
     This is free software; you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public
	 License as published by the Free Software Foundation; either
     version 2 of the License, or (at your option) any later version.
 
     This software is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     Lesser General Public License for more details.
     
 Description : Declares container control for application.
 ============================================================================
 */

#ifndef STOPWATCHCONTAINER_H
#define STOPWATCHCONTAINER_H

// INCLUDES
#include <coecntrl.h>
#include "view/OnClickListener.h"
#include "service/OnTickListener.h"

// FORWARD DECLARATIONS
// CLASS DECLARATION
namespace service
	{
	class TimerService;
	}

/**
 *  CstopwatchContainer  container control class.
 *  
 */
class CStopwatchView : public CCoeControl, MCoeControlObserver,
                       view::OnClickListener, service::OnTickListener
	{
public:
	// Constructors and destructor

	/**
	 * EPOC default constructor.
	 * @param aRect Frame rectangle for container.
	 */
	void ConstructL(const TRect& aRect);

	/**
	 * Destructor.
	 */
	~CStopwatchView();

public:
	// New functions

public:
	// Functions from base classes
public:
	// implement view::OnClickListener
	virtual void OnClick(CCoeControl* aView);
	TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType);
	
private:
	// Functions from base classes

	/**
	 * From CoeControl,SizeChanged.
	 */
	void SizeChanged();

	/**
	 * From CoeControl,CountComponentControls.
	 */
	TInt CountComponentControls() const;

	/**
	 * From CCoeControl,ComponentControl.
	 */
	CCoeControl* ComponentControl(TInt aIndex) const;

	/**
	 * From CCoeControl,Draw.
	 */
	void Draw(const TRect& aRect) const;

	/**
	 * From MCoeControlObserver
	 * Acts upon changes in the hosted control's state. 
	 *
	 * @param	aControl	The control changing its state
	 * @param	aEventType	The type of control event 
	 */
	void HandleControlEventL(CCoeControl* aControl, TCoeEvent aEventType);
	
protected:
	virtual void OnTick(TUint32 aMills);
	void OnReset();
	void OnStart();
	void OnStop();
	void OnNext();
	
private:
	void DrawBackground(CWindowGc& aGc, const TRect& aInvalid) const;
	void DrawTimer(CWindowGc& aGc, const TRect& aRect) const;
	void DrawDigit(CWindowGc& aGc, TUint8 aDigit, TRect& aRect) const;
	void DrawSmallDigit(CWindowGc& aGc, TUint8 aDigit, TRect& aRect) const;
	void DrawUpperCommas(CWindowGc& aGc, TRect& aRect) const;
	
	void DrawRecords(CWindowGc& aGc, const TRect& aRect) const;
	
	void Scroll(TInt aStep);
	
	inline TRect GetTimerArea() const;	
	inline TRect GetRecrodArea() const;
	inline TRect GetButtonArea() const;

	static void MillsToTime(TUint32 aMills, TUint32& aMin, 
				TUint32& aSec, TUint32& aQuarter);
	
private:
	//data
	RArray<TUint32>                 iRecords;
	RPointerArray<CCoeControl>      iControls;
	TUint32                         iSpanInMills;
	service::TimerService          *iTimerService;
	TInt                            iScrollRecordBottom;
	};

#endif // STOPWATCHCONTAINER_H

